package dongshi.daddy.proxy.v2.statics;

import dongshi.daddy.proxy.v2.AnimalService;
import dongshi.daddy.proxy.v2.common.Transaction;

public class AnimalServiceProxy implements AnimalService {

	//目标类
	private AnimalService animalService;

	//增强类
	private Transaction transaction;

	//利用构造函数将目标类和增强类注入
	public AnimalServiceProxy(AnimalService animalService, Transaction transaction) {
		this.animalService = animalService;
		this.transaction = transaction;
	}
	
	@Override
	public void saveAnimal() {
		// 这是每个类都需要的操作(PersonService写过一遍了，这里又要再写一遍，好痛苦！！！)
		transaction.beginTransaction();
		animalService.saveAnimal();
		// 这是每个类都需要的操作(PersonService写过一遍了，这里又要再写一遍，好痛苦！！！)
		transaction.commit();
	}
}